package cn.cycleif.aspect;

import cn.cycleif.app.service.RedisService;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;

/**
 * @Date: 25/2/11-16:52
 * @Desc:
 */
@Aspect
@Configuration
@Order(3)
public class HyperLogLimitAspect {

  @Autowired
  private RedisService redisService;

  @Pointcut("@annotation(cn.cycleif.aspect.HyperLogLimit)")
  public void serviceAspect() {
  }

  @Around("serviceAspect()")
  public Object around(ProceedingJoinPoint joinPoint) {
    Object[] object = joinPoint.getArgs();
    Object   id     = object[0];
    Object   obj    = null;
    try {
      redisService.addQuestionViewCount((Integer) id);
      obj = joinPoint.proceed();
    } catch (Throwable e) {
      e.printStackTrace();
    }
    return obj;
  }
}